<div class="box box-skin main-content">
	<div class="box-body no-padding">
	    <div class="treetable-toolbar" id="toolbar">
			<div class="form-inline" role="form">
		    	<div class="form-group btn-group">
					<button type="button" class="btn btn-default btn-flat" onclick="CRUDCategoryFunc(1);" title="添加"><i class="fa fa-plus"></i></button>
					<button type="button" class="btn btn-default btn-flat" onclick="reloadFunc();" title="重新加载"><i class="fa fa-refresh"></i></button>
				</div>
				<div class="form-group btn-group">
					<button type="button" class="btn btn-default btn-flat" onclick="expandAll();" title="全部展开"><i class="fa fa-expand"></i></button>
					<button type="button" class="btn btn-default btn-flat" onclick="collapseAll();" title="全部折叠"><i class="fa fa-compress"></i></button>
				</div>
				<div class="form-group btn-group">
					<button type="button" class="btn btn-default btn-flat" onclick="batUpdateCatCache();" title="批量更新缓存"><i class="fa fa-history"></i></button>
				</div>
            </div>
	    </div>
		<table class="table table-hover treetable"></table>
	</div>
</div>

<script type="text/javascript" src="__TMPL__Public/pages/content/category.js"></script>
<script type="text/javascript">
var xtt;
$(function() {
	var columns = [{
        title: '名称',
        field: 'name',
    }, {
		title : '类型',
		field : 'type',
        formatter: function(value, row, index) {
        	var str = '';
        	if (value == 1) {
        		str = '<span class="label label-info">栏目</span>';
        	} else if (value == 2) {
        		str = '<span class="label label-success">列表</span>';
        	} else if (value == 3) {
        		str = '<span class="label label-warning">单页</span>';
        	} else if (value == 4) {
        		str = '<span class="label label-default">外链</span>';
        	}
			return str;
        },
    }, {
        title: '模型名',
        field: 'model_name',
        formatter: function(value, row, index) {
        	return value != '' ? value : '<span class="text-gray">无</span>';
		},
    }, {
		title : '前台菜单',
		field : 'is_menu',
        formatter: function(value, row, index) {
        	return value == 0 ? '<span class="label label-default">否</span>' : '<span class="label label-success">是</span>';
		},
    }, {
		title : '静态化',
		field : 'is_html',
        formatter: function(value, row, index) {
        	return value == 0 ? '<span class="label label-default">否</span>' : '<span class="label label-success">是</span>';
		},
    }, {
        title: '访问链接',
        field: 'url',
    }, {
		title : '栏目模板',
		field : 'tpl_column',
        formatter: function(value, row, index) {
        	return value != '' ? value : '<span class="text-gray">无</span>';
		},
    }, {
		title : '列表模板',
		field : 'tpl_list',
        formatter: function(value, row, index) {
        	return value != '' ? value : '<span class="text-gray">无</span>';
		},
    }, {
        title: '单页模板',
        field: 'tpl_single',
        formatter: function(value, row, index) {
        	return value != '' ? value : '<span class="text-gray">无</span>';
		},
    }, {
        title: '操作',
        field: 'operate',
        formatter: function(value, row, index) {
			var str = '';
			str += '<div class="btn-group">';
			str += '<button type="button" class="btn btn-default btn-flat btn-xs" onclick="CRUDCategoryFunc(2, ' + row.id + ');">查看</button>';
			str += '<button type="button" class="btn btn-default btn-flat btn-xs" onclick="CRUDCategoryFunc(3, ' + row.id + ', ' + index + ');">编辑</button>';
			str += '<button type="button" class="btn btn-default btn-flat btn-xs" onclick="CRUDCategoryFunc(4, ' + row.id + ');">删除</button>';
			str += '</div>';
			return str;
		},
    }];

	xtt = xtreetable('.treetable', {
		url: "{:U('Content/Category/getAll')}",
		columns: columns,
		ajaxDataFilter: function(data) {
			return data.obj;
        },
	});
});

/* reload */
function reloadFunc() {
	xtt.refresh();
}

/* expandAll & collapseAll */
function expandAll() {
	xtt.expandAll();
}
function collapseAll() {
	xtt.collapseAll();
}
</script>
